package me.leiusual.sharing.ui.mine

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import me.leiusual.sharing.api.model.InviteQRCode
import me.leiusual.sharing.pref.User
import me.leiusual.sharing.repository.UserRepository
import me.leiusual.sharing.repository.model.Data
import me.leiusual.sharing.util.extension.toLiveData
import javax.inject.Inject

/**
 * Create by leiusual on 2018/7/16
 */
class MineInviteViewModel @Inject constructor(
    userRepository: UserRepository,
    val user: User
) : ViewModel() {

  private val _inviteQRCode = MutableLiveData<Unit>()
  val inviteQRCode: LiveData<Data<InviteQRCode.Response>> = Transformations.switchMap(_inviteQRCode) {
    userRepository.inviteQRCode().toLiveData()
  }

  fun inviteQRCode() {
    _inviteQRCode.value = Unit
  }
}